package com.springbootstart;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.DispatcherServlet;

import javax.servlet.Servlet;

@Component
public class MyServlet implements ApplicationContextAware {
    private static ApplicationContext applicationContext;

    public static Servlet getServlet() {
        DispatcherServlet bean = applicationContext.getBean(DispatcherServlet.class);
        return bean;
    }


    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }
}
